package com.qiangesoft.blog.controller.manage;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.qiangesoft.blog.common.annotation.OperationLog;
import com.qiangesoft.blog.common.mvc.PageQuery;
import com.qiangesoft.blog.common.mvc.PageResultVO;
import com.qiangesoft.blog.common.result.ResponseResult;
import com.qiangesoft.blog.core.entity.BlogFriendChain;
import com.qiangesoft.blog.core.service.IBlogFriendChainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 友情链接表 前端控制器
 * </p>
 *
 * @author qiange
 */
@RestController
@RequestMapping("/system/friend")
@Api(tags = "友情链接后端-接口")
@RequiredArgsConstructor
public class BlogFriendChainController {

    private final IBlogFriendChainService friendLinkService;

    @GetMapping(value = "/list")
    @ApiOperation(value = "友链列表")
    public PageResultVO<BlogFriendChain> list(@Validated PageQuery pageQuery, String name, Integer status) {
        return friendLinkService.listFriendLink(pageQuery, name, status);
    }

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ApiOperation(value = "添加友链", httpMethod = "POST", response = ResponseResult.class, notes = "添加友链")
    @OperationLog(value = "添加友链")
    public ResponseResult insert(@RequestBody BlogFriendChain friendLink) {
        return friendLinkService.insertFriendLink(friendLink);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(value = "修改友链", httpMethod = "POST", response = ResponseResult.class, notes = "修改友链")
    @OperationLog(value = "修改友链")
    public ResponseResult update(@RequestBody BlogFriendChain friendLink) {
        return friendLinkService.updateFriendLink(friendLink);
    }

    @RequestMapping(value = "/remove", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除友链", httpMethod = "DELETE", response = ResponseResult.class, notes = "删除友链")
    @OperationLog(value = "删除友链")
    public ResponseResult deleteBatch(@RequestBody List<Integer> ids) {
        return friendLinkService.deleteBatch(ids);
    }

    @RequestMapping(value = "/top", method = RequestMethod.GET)
    @ApiOperation(value = "置顶友链", httpMethod = "GET", response = ResponseResult.class, notes = "置顶友链")
    @OperationLog(value = "置顶友链")
    public ResponseResult top(Long id) {
        return friendLinkService.top(id);
    }
}

